import constant from '@/store/constant.js'
import common from '@/store/common.js'
const baseUrl=constant.baseUrl;


export default {
	state:{//存放状态
	
		newsList:[{
					colorClass: 'uni-bg-red',
					url: '../../static/aa.png',
					content: '重要通知111'
				},
				{
					colorClass: 'uni-bg-green',
					url: '../../static/aa.png',
					content: '内容 B222'
				},
				{
					colorClass: 'uni-bg-blue',
					url: '../../static/aa.png',
					content: '内容 C33'
				},
				
				{
					colorClass: 'uni-bg-blue',
					url: '../../static/aa.png',
					content: '内容 C3344'
				}
			],
		selectNewsId:0,
		newsDetail:{
			title:"title",
			image:"",
			content:"123",
		},
		
	},
	mutations: {
		loadNewsDetailData(state,data){
			state.newsDetail=data;
		},
		loadNewsData(state,data){
			state.newsList=data
		},
		selectNews(state,data){
			state.selectNewsId=data;
		}
		
	},
	actions:{
		loadNewsDetailData(context,value){
			
			uni.request({
				url: baseUrl+'/api/news/getNewsDetail',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data: {"id":value},
				success: (res) => {
					if(res.data.code==0){
					
						context.commit('loadNewsDetailData',res.data.result)
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
		},
		loadNewsData(context){
		
		
			uni.request({
				url: baseUrl+'/api/news/getNewsList',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data: {"systemType":1},
				success: (res) => {
					console.log(JSON.stringify(res.data))
					if(res.data.code==0){
					
						context.commit('loadNewsData',res.data.result)
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
			
		},
		loadIconsData(context,func){
		
		
			uni.request({
				url: baseUrl+'/api/userCenter/getIcons',
				method: 'GET',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				
				success: (res) => {
					console.log(JSON.stringify(res.data))
					if(res.data.code==0){
					
						
						func(res.data.result);
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
			
		},
		
		
	}
}